package com.examplemartin.jpademo.pojo.po.supplier;

import com.examplemartin.jpademo.annotation.EntityCheck;
import com.examplemartin.jpademo.pojo.admin.BaseEntity;
import com.examplemartin.jpademo.pojo.po.good.GoodPO;
import com.examplemartin.jpademo.pojo.po.purchase.PurPO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import java.util.List;
import javax.persistence.*;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 供应商实体
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Entity(name = "t_supplier")
public class SupplierPO extends BaseEntity implements Serializable {

  public static Integer SUPPLIER_STATUS_LOCKED = -1;
  public static Integer SUPPLIER_STATUS_NORMAL = 1;

  @EntityCheck(required = true, errRequired = "必须输入供应商名")
  private String name;
  private String address;
  private String linkman;
  private String phone;
  private String email;
  private Integer status = SUPPLIER_STATUS_NORMAL;
  private String comment;

  @ManyToMany(cascade = CascadeType.REFRESH,fetch = FetchType.EAGER)
  @Column(nullable = true)
  @JsonProperty(value = "good")
  @OrderColumn
  private List<GoodPO> good;

  // 采购订单 list
  @JsonIgnore
  @OneToMany(mappedBy = "supplierPO")
  private List<PurPO> purPOList;



  @Override
  public String toString() {
    return "SupplierPO{" +
            "name='" + name + '\'' +
            ", address='" + address + '\'' +
            ", linkman='" + linkman + '\'' +
            ", phone='" + phone + '\'' +
            ", email='" + email + '\'' +
            ", status=" + status +
            ", comment='" + comment + '\'' +
            '}';
  }
}
